from models import User

def getUser(key):
	if key is None:
		import random
		alphabet = 'abcdefghijklmnopqrstuvwxyz'
		alphabet = alphabet + alphabet.upper()
		alphabet = alphabet + '1234567890'
		min = 10
		max = 15
		total = 2
		string=''
		for count in xrange(1,total):
		  for x in random.sample(alphabet,random.randint(min,max)):
		      string+=x
		newUser = User(key=string)
		newUser.save()
		return newUser
	else:
		result = User.objects.filter(key=key)
		if len(result) == 0:
			return None
		else:
			return result[0]
		